package com.lh0811.forge.dependency.security.client.component.provide.impl;

import com.lh0811.forge.dependency.security.client.component.provide.ProvideResToSecurityClient;
import com.lh0811.forge.dependency.security.core.model.properties.SecurityBootProperties;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


/**
 * @author lh0811
 * @date 2021/5/25
 */
@Slf4j
public class DefaultProvideResToSecurityClient implements ProvideResToSecurityClient {

    @Resource
    private SecurityBootProperties properties;

    @Override
    public String getTokenFromApplicationContext() {
        ServletRequestAttributes ra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = ra.getRequest();
        String header = request.getHeader(properties.getTokenKey());
        return header;
    }

}
